Include(App.AppPath+"\\mode\\markdown\\Markdown.Converter.js")
Include(App.AppPath+"\\mode\\markdown\\Markdown.Extra.js")

var doc=App.ActiveDoc;
var text = doc.Text

var converter = new Markdown.Converter();
Markdown.Extra.init(converter);
var html = converter.makeHtml(text);

var fso = new ActiveXObject("Scripting.FileSystemObject")
var temp_folder=fso.GetSpecialFolder(2);//temp folder
var preview=temp_folder + "\\preview.html";//preview current buffer in temp folder

var file = new ActiveXObject("Adodb.Stream");
file.Type = 2;
file.Open();
file.Charset = "utf-8";

var css=App.AppPath+"\\mode\\markdown\\" + "default.css";
var prettify_js=App.AppPath+"\\mode\\markdown\\" + "prettify.js";
var prettify_css=App.AppPath+"\\mode\\markdown\\" + "prettify.css";
var jquery_js=App.AppPath+"\\mode\\markdown\\" + "jquery-1.10.2.min.js";

var header="\
<!doctype html public '-//W3C//DTD HTML 4.0 Transitional //EN'>\n\
<html>\n\
<head>\n\
<title>Markdown Preview of EverEdit</title>\n\
<meta charset='UTF-8' />\n\
<meta name='generator' content='EverEdit' />\n\
<link href='" + css + "' rel='stylesheet'></link>\n\
<link href='" + prettify_css + "' rel='stylesheet'></link>\n\
<script type='text/javascript' src='" + prettify_js + "'></script>\n\
<script type='text/javascript' src='" + jquery_js + "'></script>\n\
</head>\n\
<body>\n";

var footer="\n\
<script type='text/javascript'>\n\
$(document).ready(function(){\n\
  if($('code').length>0){\n\
    $('code').parent().addClass('prettyprint');\n\
    prettyPrint();\n\
};\n\
});\n\
</script>\n\
</body>\n\
</html>";

file.WriteText(header);
file.WriteText(html);
file.WriteText(footer);
file.SaveToFile(preview,2);
file.Close();

var shell = new ActiveXObject("WScript.Shell")
shell.Run( preview )
